home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 7: Sunsite / Linux Cubed Series 7 - Sunsite Vol 1.iso / system / admin / linuxcon.000 / linuxcon / linuxconf-1.6 / mailconf / confread.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-06-18  |  3.0 KB  |  106 lines

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include "../misc/misc.h"
  5. #include "internal.h"
  6. #include "../paths.h"
  7.  
  8. static const char MAILCONF[] = "mailconf";
  9.  
  10. static const char *confread_getval (const char *key, const char *defval)
  11. {
  12.     const char *val = linuxconf_getval(MAILCONF,key);
  13.     if (val == NULL){
  14.         val = defval;
  15.     }
  16.     return val;
  17. }
  18.  
  19. static int confread_getval(const char *key, int defval)
  20. {
  21.     char valstr[20];
  22.     sprintf (valstr,"%d",defval);
  23.     return atoi(confread_getval(key,valstr));
  24. }
  25.  
  26. static void confread_getall (const char *key, SSTRINGS &strs)
  27. {
  28.     linuxconf_getall (MAILCONF,key,strs,1);
  29. }
  30.  
  31. static const char DNSNEEDED[] = "dnsneeded";
  32. static const char NODNS[] = "nodns";
  33. static const char UUCPNOBATCH[] = "uucpnobatch";
  34. static const char DBFORMAT[] = "dbformat";
  35. static const char DONTMASQUE[] = "dontmasque";
  36. static const char DELIVERLOCAL[] = "deliverlocal";
  37. static const char SMARTHOST[] = "smarthost";
  38. static const char MAILHOST[] = "mailhost";
  39. static const char SMARTMAILER[] = "smartmailer";
  40. static const char ALIASES[] = "aliases";
  41. static const char MAILAS[] = "mailas";
  42. static const char UUCPMAX[] = "uucpmax";
  43. static const char DELIVER[] = "deliver";
  44.  
  45. PUBLIC MAILCONF::MAILCONF()
  46. {
  47.     features.uucpmax = confread_getval(UUCPMAX,200000);
  48.     features.dnsneeded = confread_getval(DNSNEEDED,0);
  49.     features.nodns = confread_getval(NODNS,0);
  50.     features.uucpnobatch = confread_getval(UUCPNOBATCH,1);
  51.     features.dbformat.setfrom (confread_getval(DBFORMAT,"dbm"));
  52.     users.dontmasque.setfrom (confread_getval(DONTMASQUE,"root"));
  53.     users.deliverlocal.setfrom (confread_getval(DELIVERLOCAL,"root"));
  54.     smarthost.setfrom (confread_getval(SMARTHOST,""));
  55.     mailhost.setfrom (confread_getval(MAILHOST,""));
  56.     smartmailer.setfrom (confread_getval(SMARTMAILER,"smtp"));
  57.     confread_getall (ALIASES,alias);
  58.     mailas.setfrom (confread_getval(MAILAS,""));
  59.     while (alias.getnb()<NB_ALIAS) alias.add (new SSTRING);
  60.     deliver.setfrom (confread_getval(DELIVER,""));
  61. }
  62.  
  63. static void confread_replace (const char *key, const char *val)
  64. {
  65.     linuxconf_replace (MAILCONF,key,val);
  66. }
  67.  
  68. static void confread_replace (const char *key, const SSTRING &val)
  69. {
  70.     confread_replace (key,val.get());
  71. }
  72.  
  73. static void confread_replace (const char *key, int val)
  74. {
  75.     char valstr[10];
  76.     sprintf (valstr,"%d",val);
  77.     confread_replace (key,valstr);
  78. }
  79.  
  80. static void confread_replace (const char *key, const SSTRINGS &vals)
  81. {
  82.     linuxconf_replace (MAILCONF,key,vals);
  83. }
  84.  
  85. /*
  86.     Write /etc/conf.sendmail
  87. */
  88. PUBLIC int MAILCONF::write()
  89. {
  90.     confread_replace (DNSNEEDED,features.dnsneeded);
  91.     confread_replace (UUCPMAX,features.uucpmax);
  92.     confread_replace (NODNS,features.nodns);
  93.     confread_replace (UUCPNOBATCH,features.uucpnobatch);
  94.     confread_replace (DBFORMAT,features.dbformat);
  95.     confread_replace (MAILHOST,mailhost);
  96.     confread_replace (SMARTHOST,smarthost);
  97.     confread_replace (SMARTMAILER,smartmailer);
  98.     confread_replace (MAILAS,mailas);
  99.     confread_replace (DELIVERLOCAL,users.deliverlocal);
  100.     confread_replace (DONTMASQUE,users.dontmasque);
  101.     confread_replace (ALIASES,alias);
  102.     confread_replace (DELIVER,deliver);
  103.     return linuxconf_save();
  104. }
  105.  
  106.